﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class UIDisplay : MonoBehaviour {

	public UIManager uiManager;
	public List<GameObject> ingameUIbtns;
	public List<GameObject> ingameUI; //--for hide functionality

	void Awake()
	{
		uiManager = FindObjectOfType<UIManager> ();
		for(int i=0; i<ingameUIbtns.Count; i++)
		{
			ingameUIbtns[i].GetComponent<UIButtonMessage>().target = GameObject.Find ("UIManager");
		}

		ingameUI [0] = GameObject.Find ("TextboxUI");
		ingameUI [1] = GameObject.Find ("NameTextboxUI");
		ingameUI [2] = GameObject.Find ("GameUI");
	}
	void Update()
	{
		uiManager = FindObjectOfType<UIManager>();

		ingameUIbtns [0].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [1].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [2].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [3].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [4].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [5].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [6].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [7].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [8].GetComponent<UIButtonMessage> ().target = GameObject.Find("UIManager");
		ingameUIbtns [0].GetComponent<UIButtonMessage> ().functionName = "OnAudio";
		ingameUIbtns [1].GetComponent<UIButtonMessage> ().functionName = "OnSkip";
		ingameUIbtns [2].GetComponent<UIButtonMessage> ().functionName = "OnAuto";
		ingameUIbtns [3].GetComponent<UIButtonMessage> ().functionName = "OnQLoad";
		ingameUIbtns [4].GetComponent<UIButtonMessage> ().functionName = "OnQSave";
		ingameUIbtns [5].GetComponent<UIButtonMessage> ().functionName = "OnSettings";
		ingameUIbtns [6].GetComponent<UIButtonMessage> ().functionName = "OnQuit";
		ingameUIbtns [7].GetComponent<UIButtonMessage> ().functionName = "OnSave";
		ingameUIbtns [8].GetComponent<UIButtonMessage> ().functionName = "OnLoad";

		uiManager.dialogueManager.OnAuto ();

		if(Application.loadedLevelName == "PuzzleRoom")
		{
			uiManager = GameObject.Find("UIManager").GetComponent<UIManager>();
			//dmManager.dm.setDialogueID(DialoguerDialogues.First_Puzzle_Items);
		}
	}

	void FixedUpdate()
	{
		uiManager.dialogueManager.OnSkip ();
		uiManager.dialogueManager.skip ();
	}

	public void hideUI()
	{
		for(int i=0; i < ingameUI.Count; i++)
		{
			ingameUI[i].SetActive(false);
		}
	}

	public void showUI()
	{
		for(int i=0; i < ingameUI.Count; i++)
		{
			ingameUI[i].SetActive(true);
		}
	}

	void OnLevelWasLoaded(int level)
	{
		uiManager = FindObjectOfType<UIManager> ();
	}
}
